<?php		ob_start();
  /***************************************************************************************************
     PROGRAM DESCRIPTION :  PROGRAM TO VIEW AND EDIT THE AFFILIATES (PROCESSING PAGE)
      VARIABLES          :  	page          =page no
   							 	action        = elements selected
  							  	joinstatus    =join pgm status
    							count1        =elements selected
    							today         =tdaydate("Y-m-d");
    							temp          =counter;
   								cmd           =action selected

  //*************************************************************************************************/

  include_once '../includes/constants.php';
  include_once '../includes/functions.php';
  include_once '../includes/session.php';
  include_once '../includes/allstripslashes.php';


    $partners=new partners;
    $partners->connection($host,$user,$pass,$db);



    //$elements      =trim($_POST['elements[]']);
    /*******************************variables**********************************/
    $page          =trim($_GET['page']);                  //page no
    $action        =trim($_GET['id']);                    // elements selected
    $action        =explode("~",$action);
    $joinstatus    =trim($_GET['joinstatus']);            //join pgm status
    $count1        =count($_POST['elements']);                     //elements selected
    $today         =date("Y-m-d");
    $temp          =0;
    $cmd           =trim($_POST['sub']);                  //action selected
    if (empty($cmd))
         $cmd      =trim($_GET['sub']);

	//Added by DPT on Aug/09/05
	//get action selected from the hidden variable
	$cmd			= $_POST['hidden_choice'];
	$choice			= $_GET['choice'];
	$pgmid			= $_GET['pgmid'];
	
	//Rejoin after blocking programs
	if($choice=="rejoin")
	{
		  //-----------getting affiliate approval type---------
		  $sql1		=	"select * from partners_pgmstatus where pgmstatus_programid='$pgmid'";
		  $result	=	mysql_query($sql1);
		  $row		=	mysql_fetch_object($result);
		  $approval	=	$row->pgmstatus_affiliateapproval;
	//	  if($approval=="automatic")
			 	$approvalstatus	=	"approved";          // automatic approval
//		  else
		//	  	$approvalstatus	=	"waiting";          //manuall approval
		  //-----------getting affiliate approval type---------		
		  
		  //update new status
		  $sql	=	"update partners_joinpgm set joinpgm_status='$approvalstatus' where joinpgm_programid=$pgmid and joinpgm_affiliateid=".$_SESSION['AFFILIATEID'];
		  mysql_query($sql);	  
		 
		  //redirect back
		  header("location:index.php?Act=Affiliates&page=$page&joinstatus=$joinstatus");
		  exit;
	}
	//Added by DPT on Aug/09/05

    /***************************************************************************/



    /****************************actions***************************************/

     switch($cmd)
               {
                  case 'Join Selected':     //join pgm(through check all)

                       while ($temp<$count1) //all selected pgms
                        {

                          $id=explode("~",$_POST['elements'][$temp]);     //joinid+pgmid+status



                          /********getting affilaite approval type*************/
                          $sql1="select * from partners_pgmstatus where pgmstatus_programid='$id[2]'";
                          $result=mysql_query($sql1)or die($sql1."<br/>".mysql_error());
                          $row=mysql_fetch_object($result);
                          $approval=$row->pgmstatus_affiliateapproval;
                          //if($approval=="automatic")
                             $approvalstatus="approved";          // automatic approval
                          //else
                            //  $approvalstatus="waiting";          //manuall approval
                          /****************************************************/



                          /*******checking for not joined pgms*****************/
                          if($id[1]=='notjoined')
                            {
                             $sql="insert partners_joinpgm(joinpgm_programid,joinpgm_merchantid,joinpgm_affiliateid,joinpgm_status,joinpgm_date) values ($id[2],$id[3],$AFFILIATEID,'$approvalstatus','$today')  ";
                             mysql_query($sql);
                            }
                          /******************************************************/


                          $temp++;   //next element
                        }

                       break;

                 case 'Suspend Selected':                  //suspend(check all)

                       while ($temp<$count1)               //all elements
                        {
                          $id=explode("~",$_POST['elements'][$temp]); //joinid+pgmid+status


                          /**********checking for approval*********************/
                          if($id[1]=='approved')
                            {
                             $sql="update partners_joinpgm set joinpgm_status='suspend' where joinpgm_programid=$id[2] and joinpgm_affiliateid=$AFFILIATEID ";
                            //echo $sql;
                             mysql_query($sql);
                            }
                          /****************************************************/


                          $temp++;         //next element
                        }
                       break;

                 default:    //join selected pgm

                       /********checking for not joined pgm********************/
                       if($action[1]=='notjoined')
                         {

                         /************getting approval type********************/
                          $sql1="select * from partners_pgmstatus where pgmstatus_programid=$action[2]";
                          $result=mysql_query($sql1)or die($sql1."<br/>".mysql_error());
                          $row=mysql_fetch_object($result);
                          $approval=$row->pgmstatus_affiliateapproval;//getting affilaite approval type

                          //if($approval=="automatic")
                             $approvalstatus="approved";         //automatic approval
                          //else
                            //  $approvalstatus="waiting";         //manual approval
                         /*****************************************************/


                             $sql="insert partners_joinpgm(joinpgm_programid,joinpgm_merchantid,joinpgm_affiliateid,joinpgm_status,joinpgm_date) values ($action[2],$action[3],$AFFILIATEID,'$approvalstatus','$today')  ";
                              mysql_query($sql);
                         }
                         /********close checking for not joined pgm************/


                      break;

         }
         /*********************************************************************/

      header("location:index.php?Act=Affiliates&page=$page&joinstatus=$joinstatus");  //redirecting

?>